<?php
/**
 * @purpose: 对“请求”类型中子类型为4（app_common）的编码与解码文件
 * @author: Mandel Woo <wuzhijian@snda.com>
 *
 * @memo: 参考mother_board_typex.php
 */

require_once(dirname(__FILE__)."/../../../models/user/UCModUserInfo.php");


function msg_request_type4_encoder() {
	$fields = array("msg");

	foreach($fields as $k => $v) {
		eval("\${$v}=func_get_arg($k);");
	}


	return serialize(array(
			"msg"  => utf_substr($msg, 495),
			));
}

function msg_request_type4_decoder() {
	$fields = array("id","senderid","receiverid","content","createTime","changeFlag","fmt");

	foreach($fields as $k => $v) {
		eval("\${$v}=func_get_arg($k);");
	}

	$data = unserialize($content);
	$msg  = strip_tags($data['msg'], "<p><br><a><b><i>");


	$users_infos = UCModUserInfo::getUserInfos(array($senderid, $receiverid), array(USERINFO_NICKNAME,USERINFO_AVATAR_45));

	$seduser_nickname = htmlspecialchars($users_infos[$senderid][USERINFO_NICKNAME]);
	$seduser_nickname == '' && $seduser_nickname = $senderid;

	$sender_url = get_user_home_url($senderid);
	$sender     = "<a href=\"{$sender_url}\" target='_blank'>{$seduser_nickname}</a>";

	if ($fmt == 'line') {
		return utf_substr(strip_tags($msg), 80);


	} else if ($fmt == 'box') {
		$time = UCModMessageMgr::fmtTime($createTime, 2);


		echo <<<HTML
<div class="emailUserList">
	<img src="{$users_infos[$receiverid][USERINFO_AVATAR_45]}" class="avatar-45" />
	<img src="{$users_infos[$senderid][USERINFO_AVATAR_45]}" class="avatar-45" />
	<div class="clear"></div>
</div>
<div class="emailQues">
	<h3 class="game"><span class="r">{$time}</span>{$msg}</h3>
</div>
HTML;

		return $html;


	} else {
		return "";
	}
}


